//index.js
//获取应用实例
var app = getApp();
Page({
  data: {
    apiurl: app.data.apiurl,
    type: '',
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    openid: app.globalData.openid,
    userInfo: app.globalData.userInfo 
  },
  toggle: function (e) {
    var that = this;
    var type = that.data.type === '领取成功' ? '已领取' : '领取成功';
    that.setData({
      type: type
    });
    setTimeout(function () {
      that.setData({
        type: ''
      });
    }, 1500)
    // console.log(e.currentTarget.dataset.money);
    // console.log('111'+app.globalData.openid);
    //领取优惠券
    wx.request({
      url: getApp().data.apiurl + '/index.php/index/index/receivecoupons?rcoupon=' + e.currentTarget.dataset.money+'&ropenid='+app.globalData.openid,
      data: {
        //  rcoupon: e.currentTarget.dataset.money, openid: app.globalData.openid
         },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res);
      }
    });
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    showView: (options.showView == "true" ? true : false);
    var that = this;

    //轮播图
    wx.request({
      url: getApp().data.apiurl + '/index.php/index/index/banner',
      data: {
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          banner: res.data,
        });
      }
    });
    //优惠券
    wx.request({
      url: getApp().data.apiurl +'/index.php/index',
      data: {
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          coupon: res.data,
        });
      }
    });
    //热卖推荐
    wx.request({
      url: getApp().data.apiurl + '/index.php/index/index/hotgoods',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          hotgoods: res.data,
        });
      }
    });
  },
   onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '美丽誓颜商城',
      path: '/pages/index/index',
      success: function (res) {
        wx.showToast({
          title: '转发成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: function (res) {
        wx.showToast({
          title: '转发失败',
          icon: 'clear',
          duration: 2000,
          image: '../../images/tanhao.png'
        });
      }
    }
  }
})


